package com.netdisk.controller;
/**
 * 图标action 
 * 显示用户的文件图标
 * @author chenlong
 * 2013-5-16
 */
import static com.netdisk.util.IcoReader.getIcos;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;

@Component("fileIcoAction")
@Scope("prototype")
public class FileIcoAction extends ActionSupport{
	private InputStream inputStream;
	
	private String timestamp;
	
	public String getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(String timestamp) {
		this.timestamp = timestamp;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	private String icoName = new String();
	
	private String path;
	
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getIcoName() {
		return icoName;
	}

	public void setIcoName(String icoName) {
		this.icoName = icoName;
	}
	
	public InputStream getInputStream() throws FileNotFoundException {
		 if(getIcos().containsKey(icoName.toLowerCase())){
			 System.out.println(icoName);
			 this.path = getIcos().get(icoName.toLowerCase()).getAbsolutePath();
		 }else{
			 this.path = getIcos().get("unknown").getAbsolutePath();
		 }
		return new FileInputStream(this.path);
	}
	
	@Override
	public String execute() throws Exception {
		 return SUCCESS;
	}
	
	
}
